<?php
load_ctl("admin_Common");
class Admin_SinglePageController extends Admin_CommonController {
	function init(){
		parent::init();
		load_model('SinglePage');
		$this->sp = new SinglePage();
	}
	public function indexAction(){
		$this->view->title = "单页面文章信息";
		$this->view->sp_list = $this->sp->get_sp_list();
		$this->view->mainphp = 'views/scripts/admin/index/singlepage.phtml';
		echo $this->view->render("index.phtml");
	}
	public function addspAction(){
		
		Zend_Loader::loadFile("fckeditor.php",'./api/fckeditor');
		$editor = new FCKeditor("sp_content");
		$editor->BasePath   = $this->view->baseUrl.'/api/fckeditor/';
		$editor->ToolbarSet = 'Basic';
		$editor->Width      = '100%';
		$editor->Height     = '220';
		$editor->Value      = '';
		$this->view->fckeditor = $editor->Create();
		
		$this->view->action = 'add';
		$this->view->mainphp = 'views/scripts/admin/index/dosinglepage.phtml';
		echo $this->view->render("index.phtml");
	}
	public function editspAction(){
		$this->view->action = 'edit';
		$id = $this->_request->get('id');
		$this->view->sp_info = $this->sp->get_sp_info($id);
		
		Zend_Loader::loadFile("fckeditor.php",'./api/fckeditor');
		$editor = new FCKeditor("sp_content");
		$editor->BasePath   = $this->view->baseUrl.'/api/fckeditor/';
		$editor->ToolbarSet = 'Basic';
		$editor->Width      = '100%';
		$editor->Height     = '220';
		$editor->Value      = $this->view->sp_info["sp_content"];
		$this->view->fckeditor = $editor->Create();
	
		$this->view->mainphp = 'views/scripts/admin/index/dosinglepage.phtml';
		echo $this->view->render("index.phtml");
	}
	function submitspAction(){
		if($this->_request->isPost()){
			$filter = new Zend_Filter_StripTags();
			$data = array(
				'sp_title'=>$filter->filter($this->_request->getPost('sp_title')),
				'sp_content'=>$filter->filter($this->_request->getPost('sp_content')),
				'sp_date'=>time(),
			);
			$action = $this->_request->getPost('action');
			if ($action == 'edit') {	//修改
				$id = intval($filter->filter($this->_request->getPost('sp_id')));
				$this->sp->update_sp($id,$data);
				php_alert('修改文章成功');
			}else if($action == 'add') {//新增
				$this->sp->add_sp($data);
				php_alert('添加文章成功');
			}
			$this->_redirect("admin/singlepage");
		}else if(isset($_GET["action"]) && $_GET["action"] == 'del'){
			$filter = new Zend_Filter_StripTags();
			$id = intval($filter->filter($this->_request->get('id')));
			$this->sp->del_sp($id);
			php_alert('删除类别成功');
			$this->_redirect("admin/singlepage");
		}
	}
}
?>